
package jermedit.gobjekte;


import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Polygon;
import javax.swing.SwingUtilities;

public class Association extends PolygonObject {
    
//    int breite=30; // HALBE Breite 
//    int laenge=15; // HALBE Hoehe 
    
    
    public Association (int x, int y, int id){
//        super(vonX,vonY,"Association", id);
        this.x = x;
        this.y = y;
        this.name="";
        this.id = id;
        breite = 30;
        laenge = 15;
        obenmitte = new EditPoint (x, y-laenge);  
        mitterechts = new EditPoint(x+breite, y);
        mittelinks = new EditPoint (x-breite, y);
        untenmitte = new EditPoint(x, y+laenge);
        
        // BoundingBox setzen
        int x2Points[] = {x, x+breite, x, x-breite};
	int y2Points[] = {y-laenge, y, y+laenge, y};
        boundingBox = (new Polygon (x2Points,y2Points, x2Points.length)).getBounds();
         }
    
    @Override
    public void drawSub(Graphics2D g2) {
        int x2Points[] = {x, x+breite, x, x-breite};
        int y2Points[] = {y-laenge, y, y+laenge, y};
        Polygon raute = new Polygon (x2Points,y2Points, x2Points.length);	
        g2.draw(raute);

       final FontMetrics fm = g2.getFontMetrics();
       final int strWidth = SwingUtilities.computeStringWidth(fm, name);
       g2.drawString(name, x-strWidth/2, y+fm.getAscent()/2);

    }

    @Override
    public boolean isInArea(int x, int y) {
        return (this.y-laenge<y) && (y<this.y+laenge) && (this.x-breite<x) && (x<this.x+breite);
    }

    @Override
    public void move(int x, int y){
        super.move(x,y);
        // BoundingBox move
        boundingBox.move(x-breite,y-laenge);
        // EP von ZO move
        //Verschiebe die Eckpunkte zusammen mit der Association
        mittelinks.move(x-breite,y);
        obenmitte.move(x, y-laenge);
        mitterechts.move(x+breite, y);
        untenmitte.move(x, y+laenge);
    }
    @Override
    public Point mitteLinks(){
        Point liMi = new Point(x-getBreite(),y);
        return liMi;
    }
        
    @Override
    public Point mitteOben(){
        Point miOben = new Point(x,y-super.getLaenge());
        return miOben;
    }
    
    @Override
    public Point mitteRechts(){
        Point miRechts = new Point(x+getBreite(),y);
        return miRechts;
    }
    
    @Override
    public Point mitteUnten(){
        Point miUnten = new Point(x,y+super.getLaenge());
        return miUnten;
    }
    
    @Override
    public int getBreite() {
        return breite;
    }

    @Override
    public void setBreite(int breite) {
        this.breite = breite;
    }

    @Override
    public int getLaenge() {
        return laenge;
    }

    @Override
    public void setLaenge(int laenge) {
        this.laenge = laenge;
    }    
}
